package com.liar.modular.core.service;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * 获取数据库所有的表
 *
 * @author fengshuonan
 * @date 2017-12-04-下午1:37
 */
@Service
public class TableService {

//    @Value("${spring.datasource.db-name}")
//    private String dbName;
    private String dbName2="iron";
//    @Autowired
//    DruidProperties druidProperties;
//    private String url = "jdbc:mysql://192.168.1.18:3306/zy_pls?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull";
//
//    private String username = "root";
//
//    private String password = "123456";
//
//    private String driverClassName = "com.mysql.jdbc.Driver";
//    /**
//     * 获取当前数据库所有的表信息
//     */
    public List<Map<String, Object>> getAllTables() {
//        String sql = "select TABLE_NAME as tableName,TABLE_COMMENT as tableComment from information_schema.`TABLES` where TABLE_SCHEMA = '" + dbName + "'";
        String sql2 = "select TABLE_NAME as tableName,TABLE_COMMENT as tableComment from information_schema.`TABLES` where TABLE_SCHEMA = '" + dbName2 + "'";
//        System.out.println(SqlRunner.FACTORY);
//        DruidDataSource dataSource = new DruidDataSource();
//        druidProperties.config(dataSource);
//        Connection conn = null;
//        PreparedStatement preparedStatement = null;
//        try {
//            Class.forName(driverClassName); //classLoader,加载对应驱动
//            conn =DriverManager.getConnection(url, username, password);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        try {
//             preparedStatement = conn.prepareStatement(sql2);
//            ResultSet rs = preparedStatement.executeQuery();
//            int col = rs.getMetaData().getColumnCount();
//            while (rs.next()) {
//                for (int i = 1; i <= col; i++) {
//                    System.out.print(rs.getString(i) + "\t");
//                    if ((i == 2) && (rs.getString(i).length() < 8)) {
//                        System.out.print("\t");
//                    }
//                }
//
//
//            }
//            System.out.println("======================================================================================================");
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        System.out.println(SqlRunner.db().selectList(sql2));

        return SqlRunner.db().selectList(sql2);
    }
}
